package com.autonavi.yunda.yunji.groovy.test

import com.autonavi.yunda.yunji.common.utils.JsonUtils
import com.autonavi.yunda.yunji.core.code.generator.GroovyCodeGenerator
import com.autonavi.yunda.yunji.core.vo.param.NodeParam
import org.junit.jupiter.api.Test

/**
 * @author cizhong.wcs
 * @date 2024/5/24 14:46
 */
class GroovyCodeGeneratorTest {
    @Test
    void testCodeGenerate() {
        def generator = new GroovyCodeGenerator(
                "test",
                "class AAA{def process(){println \"test\"}}",
                [
                        new NodeParam("test1", "string", "test", null, true,
                                "test", "test", null, false),
                        new NodeParam("test2", "boolean", "test", null, true,
                                "test", "true", null, false),
                        new NodeParam("test3", "integer", "test", null, true,
                                "test", "123", null, false),
                        new NodeParam("test4", "object", "test", null, true,
                                "test", "{ \"name\": \"Alice\", \"age\": 30, \"properties\": { \"name\": \"Alice\", \"age\": 30 ,\"data\":\"{ \\\"name\\\": \\\"Alice\\\", \\\"age\\\": 30 }\" }, \"emp\":{}}", null, false),
                        new NodeParam("test5", "string", "test", null, true,
                                "test", "{ \"name\": \"Alice\", \"age\": 30, \"properties\": { \"name\": \"Alice\", \"age\": 30 } }", null, false),
                        new NodeParam("test6", "object", "test", null, true,
                                "test", "{}", null, false),
                ],

                "test",
                "test"
        )
        println generator.toGroovyContent()
        def obj = [ "name" : """Alice""", "age" : 30, "properties" : [ "name" : """Alice""", "age" : 30, "data" : """{ "name": "Alice", "age": 30 }""" ], "emp" : [:] ]
        println JsonUtils.toString(obj)
    }
}
